package com.example.demo0912_mybatis.config;


import com.alibaba.druid.support.jakarta.StatViewServlet;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

@Configuration
public class DruidConfig {
    @Bean
    public ServletRegistrationBean<StatViewServlet> druidServlet() {
        ServletRegistrationBean<StatViewServlet> bean = new ServletRegistrationBean<>(new StatViewServlet(), "/druid/*");
        Map<String, String> initParams = new HashMap<>();
        initParams.put("loginUsername", "admin"); // 设置监控页面的登录用户名
        initParams.put("loginPassword", "password"); // 设置监控页面的登录密码
        // 可以添加其他初始化参数，如允许访问的IP等
        bean.setInitParameters(initParams);
        return bean;
    }
}
